#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
#define ll long long


int N, M, K;
int f[1001][1001];
int 
const ll mod = 1000000007ll;
ll _x, _y;
int inv[1001];
int fact[1001];

inline void extGcd(ll a, ll b)
{
    if (b == 0)
    {
        _x = 1;
        _y = 0;
    }
    else
    {
        ll x, y;
        extGcd(b, a % b);
        x = _y;
        y = _x - (a / b) * _y;
        _x = x;
        _y = y;
    }
}
inline int invMod(int a)
{
	if (a == 0) return 1;
    extGcd(a, mod);
    _x %= mod;
    _x += mod;
    _x %= mod;
    return _x;
}

inline int F(int m, int k)
{
	if (m == 0)
	{
		if (k == 0) return 1;
		else return 0; 
	}
	if (m - 1 < k) return 0;
	ll t = ((ll)fact[m - 1] * inv[m - 1 - k]) % mod;
	t *= inv[k];
	t %= mod;
	if (k % 2) t = -t;
	if (t < 0) t += mod;
	t *= inv[m];
	t %= mod;
	return t;
}

void solve() 
{   
	K = min(M, K);
	ll res = 0;
	if (M == K)
	{
   		for (int i = 1; i <= K; i++)
   		{
	   	//	cerr << i << " ^ " << N << " with coef = " << ((fact[M] * (((ll)invMod(fact[i]) * F(M - i, K - i)) % mod)) % mod) << "\n";
   			res += (
   			((f[i][N] * (ll)inv[i]) % mod) * F(M - i, K - i))
   			 % mod;
   			if (res < 0) res += mod;
   			if (res >= mod) res -= mod;
	   	}
   		res = (res * fact[M]) % mod;
	}
	else
	{
        ll D = 1;
        for (int i = 0; i <= K; i++)
        {
        	if (i == M) break;
        	D = (D * (M - i)) % mod;
        }
        ll C;
        for (int i = 1; i <= K; i++)
        {
        	C = (D * invMod(M - i)) % mod;
        	C = (C * inv[i]) % mod;
        	C = (C * inv[K - i]) % mod;
        //	cerr << i << " " << C << "\n";
        	if ((K - i) & 1)
        		res -= (f[i][N] * C) % mod;
        	else res += (f[i][N] * C) % mod;
        	if (res < 0) res += mod;
        	if (res >= mod) res -= mod;
        }
    }
    cout << res << "\n";
}

int main()
{
	int T;                                                           
	for (int i = 0; i <= 1000; i++)
	{
		f[i][0] = 1;
		for (int j = 1; j <= 1000; j++)
			f[i][j]	= ((ll)f[i][j - 1] * i) % mod;
	}
	inv[0] = 1;
	fact[0] = 1;
	for (int i = 1; i <= 1000; i++)
	{
		fact[i] = (fact[i - 1] * (ll)i) % mod;
		inv[i] = ((ll)inv[i - 1] * invMod(i)) % mod;
	}
	cin >> T;
	for (int i = 0; i < T; i++)
	{
		cin >> N >> M >> K;
		solve();
	}
	return 0;

}